// Create the local library object, to be exported or referenced globally later
const lib = {};

/**
 *
 * @param arr
 * @returns {*}
 */
lib.bubbleSort = function(arr, comparer) {
  var len = arr.length;
  for (var i = 0; i < len; i++) {
    for (var j = 0; j < len - 1 - i; j++) {
      if (comparer) {
        if (comparer(arr[j], arr[j + 1])) {
          var temp = arr[j + 1];
          arr[j + 1] = arr[j];
          arr[j] = temp;
        }
      } else {
        if (arr[j] > arr[j + 1]) {
          var temp = arr[j + 1];
          arr[j + 1] = arr[j];
          arr[j] = temp;
        }
      }
    }
  }
  return arr;
};

export default lib;
